* GSS analysis for: 
* Class, Policy Attitudes and U.S. Presidential Voting in the Post-Industrial Era: The Importance of Issue Salience
* Franko & Witko
* Political Research Quarterly
* Date: 05/25/22


set more off


*******************************************************************************
* Policy effect on vote.
* Pooled models.
*******************************************************************************

* Create new frame to save results.
frame create dvotepol_diffs_gss
frame dvotepol_diffs_gss { 
	input 	str10 var diff ll ul str10 sample
		"govineq01" . . . "All"
		"culpol01" . . . "All"
		"racepol01" . . . "All"
		"govineq01" . . . "White"
		"culpol01" . . . "White"
		"racepol01" . . . "White"
		"govineq01" . . . "Nonwhite"
		"culpol01" . . . "Nonwhite"
	end
}

*******************************************************************************
* Full sample.
*******************************************************************************

local varlst1 "pid7 polviews white age female south"

foreach v in govineq01 culpol01 racepol01 {
	melogit demvote `v' `varlst1' || year: 
	estimates store dvp_`v'_gss_all
	margins , at((p95) `v') at((p5) `v') post
	lincom _b[1._at] - _b[2._at]
	frame dvotepol_diffs_gss { 
		replace diff = r(estimate) if var == "`v'" & sample == "All"
		replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "All"
		replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "All"
	}
}


*******************************************************************************
* Repeat above analysis for white only subsample.
*******************************************************************************

local varlst2 "pid7 polviews age female south"

foreach v in govineq01 culpol01 racepol01 {
	melogit demvote `v' `varlst2' if white==1 || year: 
	estimates store dvp_`v'_gss_wo
	margins , at((p95) `v') at((p5) `v') post
	lincom _b[1._at] - _b[2._at]
	frame dvotepol_diffs_gss { 
		replace diff = r(estimate) if var == "`v'" & sample == "White"
		replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "White"
		replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "White"
	}
}


*******************************************************************************
* Repeat above analysis for nonwhite subsample.
*******************************************************************************

local varlst2 "pid7 polviews age female south"

foreach v in govineq01 culpol01 {
	melogit demvote `v' `varlst2' if white==1 || year: 
	estimates store dvp_`v'_gss_nwo
	margins , at((p95) `v') at((p5) `v') post
	lincom _b[1._at] - _b[2._at]
	frame dvotepol_diffs_gss { 
		replace diff = r(estimate) if var == "`v'" & sample == "Nonwhite"
		replace ll = r(estimate) + invnorm(0.025)*r(se) if var == "`v'" & sample == "Nonwhite"
		replace ul = r(estimate) + invnorm(0.975)*r(se) if var == "`v'" & sample == "Nonwhite"
	}
}


***** Save Min/max difference results.
frame dvotepol_diffs_gss : save "results/dvotepol_diffs_gss.dta", replace



*******************************************************************************
* Allow policy coefficients to vary by year, then plot effects over time.
*******************************************************************************

*******************************************************************************
* Full sample.
*******************************************************************************

local varlst1 "pid7 polviews white age female south"

foreach v in govineq01 culpol01 racepol01 {
	melogit demvote `v' `varlst1' || year: `v' 
	estimates store dvp_`v'_gss_time
	* Estimated effects: use coefficients.
	preserve
	predict b_re* if e(sample), reffects reses(b_rese*)

	gen b = _b[`v'] + b_re1
	gen se = sqrt((_se[`v']^2) + (b_rese1^2))

	collapse b se, by(year)
	gen b_hi = b + 1.96*se
	gen b_lo = b - 1.96*se

	drop if b == .
	gen str20 var = "`v'"

	save "results/dvp_`v'_gss_time.dta", replace
	restore
}


*******************************************************************************
* Repeat above analysis for white only subsample.
*******************************************************************************

local varlst2 "pid7 polviews age female south"

foreach v in govineq01 culpol01 racepol01 {
	melogit demvote `v' `varlst2' if white==1 || year: `v' 
	estimates store dvp_`v'_gss_time_wo
	* Estimated effects: use coefficients.
	preserve
	predict b_re* if e(sample), reffects reses(b_rese*)

	gen b = _b[`v'] + b_re1
	gen se = sqrt((_se[`v']^2) + (b_rese1^2))

	collapse b se, by(year)
	gen b_hi = b + 1.96*se
	gen b_lo = b - 1.96*se

	drop if b == .
	gen str20 var = "`v'"

	save "results/dvp_`v'_gss_time_wo.dta", replace
	restore
}



preserve
clear
append using "results/dvp_govineq01_gss_time.dta" 
append using "results/dvp_culpol01_gss_time.dta" 
append using "results/dvp_racepol01_gss_time.dta" 
save "results/dvote_policy_gss_time.dta", replace
restore

preserve
clear
append using "results/dvp_govineq01_gss_time_wo.dta" 
append using "results/dvp_culpol01_gss_time_wo.dta" 
append using "results/dvp_racepol01_gss_time_wo.dta" 
save "results/dvote_policy_gss_time_wo.dta", replace
restore

